package com.guofen.controller.sjq;

import com.guofen.pojo.ShljAbnormalGarbage;
import com.guofen.pojo.SjqCompostCraft;
import com.guofen.service.sjq.SjqCompostCraftService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/sjq/compostCraft")
@Controller
@Api(tags = "SjqCompostCraftController", description = "堆肥工艺现场")
public class SjqCompostCraftController {
    @Autowired
    private SjqCompostCraftService sjqCompostCraftService;

    @ApiOperation("添加记录_")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Result add(@ApiParam(name="rawMaterial1",value="生料量",required=true) @RequestParam String rawMaterial1,
                       @ApiParam(name="peat1",value="泥炭用量",required=true) @RequestParam String peat1,
                       @ApiParam(name="backfillFertilizer1",value="回填肥用量",required=true) @RequestParam String backfillFertilizer1,
                       @ApiParam(name="woodMatrix1",value="木基质用量",required=true) @RequestParam String woodMatrix1,
                       @ApiParam(name="output1",value="出料量",required=true) @RequestParam String output1,
                       @ApiParam(name="tontankFeed2",value="#2进料吨箱数量",required=true) @RequestParam String tontankFeed2,
                       @ApiParam(name="disposalKitchenWaste2",value="#2处理厨余量",required=true) @RequestParam String disposalKitchenWaste2,
                       @ApiParam(name="peat2",value="#2泥炭用量",required=true) @RequestParam String peat2,
                       @ApiParam(name="driedKitchenWaste2",value="#2干化厨余筛下物用量",required=true) @RequestParam String driedKitchenWaste2,
                       @ApiParam(name="woodMatrix2",value="#2木基质用量",required=true) @RequestParam String woodMatrix2,
                       @ApiParam(name="dischargeTonBox2",value="#2出料吨箱数量",required=true) @RequestParam String dischargeTonBox2,
                       @ApiParam(name="kitchenWasteUnderSieve2",value="#2厨余筛下物产生量",required=true) @RequestParam String kitchenWasteUnderSieve2,
                        @ApiParam(name="tontankFeed3",value="#3进料吨箱数量",required=true) @RequestParam String tontankFeed3,
                        @ApiParam(name="disposalKitchenWaste3",value="#3处理厨余量",required=true) @RequestParam String disposalKitchenWaste3,
                        @ApiParam(name="peat3",value="#3泥炭用量",required=true) @RequestParam String peat3,
                        @ApiParam(name="driedKitchenWaste3",value="#3干化厨余筛下物用量",required=true) @RequestParam String driedKitchenWaste3,
                        @ApiParam(name="woodMatrix3",value="#3木基质用量",required=true) @RequestParam String woodMatrix3,
                        @ApiParam(name="dischargeTonBox3",value="#3出料吨箱数量",required=true) @RequestParam String dischargeTonBox3,
                        @ApiParam(name="kitchenWasteUnderSieve3",value="#3厨余筛下物产生量",required=true) @RequestParam String kitchenWasteUnderSieve3,
                        @ApiParam(name="tontankFeed4",value="#4进料吨箱数量",required=true) @RequestParam String tontankFeed4,
                        @ApiParam(name="disposalKitchenWaste4",value="#4处理厨余量",required=true) @RequestParam String disposalKitchenWaste4,
                        @ApiParam(name="peat4",value="#4泥炭用量",required=true) @RequestParam String peat4,
                        @ApiParam(name="driedKitchenWaste4",value="#4干化厨余筛下物用量",required=true) @RequestParam String driedKitchenWaste4,
                        @ApiParam(name="woodMatrix4",value="#4木基质用量",required=true) @RequestParam String woodMatrix4,
                        @ApiParam(name="dischargeTonBox4",value="#4出料吨箱数量",required=true) @RequestParam String dischargeTonBox4,
                        @ApiParam(name="kitchenWasteUnderSieve4",value="#4厨余筛下物产生量",required=true) @RequestParam String kitchenWasteUnderSieve4,
                       @ApiParam(name="remark",value="备注",required=true) @RequestParam String remark
                      ){

        if (sjqCompostCraftService.add(rawMaterial1,peat1,backfillFertilizer1,woodMatrix1,output1,tontankFeed2,disposalKitchenWaste2,peat2,driedKitchenWaste2,woodMatrix2,dischargeTonBox2,kitchenWasteUnderSieve2,tontankFeed3,disposalKitchenWaste3,peat3,driedKitchenWaste3,woodMatrix3,dischargeTonBox3,kitchenWasteUnderSieve3,tontankFeed4,disposalKitchenWaste4,peat4,driedKitchenWaste4,woodMatrix4,dischargeTonBox4,kitchenWasteUnderSieve4,remark))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("获取 当日 最新 一条记录")
    @RequestMapping(value = "/getlast_day",method = RequestMethod.GET)
    @ResponseBody
    public Result getlast_day(){
        return  ResultGenerator.genSuccessResult(sjqCompostCraftService.getlast_day());
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqCompostCraftService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="id",required=true) @RequestParam(required = true) Integer id,
                         @ApiParam(name="date",value="date",required=false) @RequestParam(required = false) String date,
                         @ApiParam(name="raw_material_1",value="raw_material_1",required=false) @RequestParam(required = false) Double raw_material_1,
                         @ApiParam(name="peat_1",value="peat_1",required=false) @RequestParam(required = false) Double peat_1,
                         @ApiParam(name="backfill_fertilizer_1",value="backfill_fertilizer_1",required=false) @RequestParam(required = false) Double backfill_fertilizer_1,
                         @ApiParam(name="wood_matrix_1",value="wood_matrix_1",required=false) @RequestParam(required = false) Double wood_matrix_1,
                         @ApiParam(name="output_1",value="output_1",required=false) @RequestParam(required = false) Double output_1,
                         @ApiParam(name="tontank_feed_2",value="tontank_feed_2",required=false) @RequestParam(required = false) Double tontank_feed_2,
                         @ApiParam(name="disposal_kitchen_waste_2",value="disposal_kitchen_waste_2",required=false) @RequestParam(required = false) Double disposal_kitchen_waste_2,
                         @ApiParam(name="peat_2",value="peat_2",required=false) @RequestParam(required = false) Double peat_2,
                         @ApiParam(name="dried_kitchen_waste_2",value="dried_kitchen_waste_2",required=false) @RequestParam(required = false) Double dried_kitchen_waste_2,
                         @ApiParam(name="wood_matrix_2",value="wood_matrix_2",required=false) @RequestParam(required = false) Double wood_matrix_2,
                         @ApiParam(name="discharge_ton_box_2",value="discharge_ton_box_2",required=false) @RequestParam(required = false) Double discharge_ton_box_2,
                         @ApiParam(name="kitchen_waste_under_sieve_2",value="kitchen_waste_under_sieve_2",required=false) @RequestParam(required = false) Double kitchen_waste_under_sieve_2,
                         @ApiParam(name="tontank_feed_3",value="tontank_feed_3",required=false) @RequestParam(required = false) Double tontank_feed_3,
                         @ApiParam(name="disposal_kitchen_waste_3",value="disposal_kitchen_waste_3",required=false) @RequestParam(required = false) Double disposal_kitchen_waste_3,
                         @ApiParam(name="peat_3",value="peat_3",required=false) @RequestParam(required = false) Double peat_3,
                         @ApiParam(name="dried_kitchen_waste_3",value="dried_kitchen_waste_3",required=false) @RequestParam(required = false) Double dried_kitchen_waste_3,
                         @ApiParam(name="wood_matrix_3",value="wood_matrix_3",required=false) @RequestParam(required = false) Double wood_matrix_3,
                         @ApiParam(name="discharge_ton_box_3",value="discharge_ton_box_3",required=false) @RequestParam(required = false) Double discharge_ton_box_3,
                         @ApiParam(name="kitchen_waste_under_sieve_3",value="kitchen_waste_under_sieve_3",required=false) @RequestParam(required = false) Double kitchen_waste_under_sieve_3,
                         @ApiParam(name="tontank_feed_4",value="tontank_feed_4",required=false) @RequestParam(required = false) Double tontank_feed_4,
                         @ApiParam(name="disposal_kitchen_waste_4",value="disposal_kitchen_waste_4",required=false) @RequestParam(required = false) Double disposal_kitchen_waste_4,
                         @ApiParam(name="peat_4",value="peat_4",required=false) @RequestParam(required = false) Double peat_4,
                         @ApiParam(name="dried_kitchen_waste_4",value="dried_kitchen_waste_4",required=false) @RequestParam(required = false) Double dried_kitchen_waste_4,
                         @ApiParam(name="wood_matrix_4",value="wood_matrix_4",required=false) @RequestParam(required = false) Double wood_matrix_4,
                         @ApiParam(name="discharge_ton_box_4",value="discharge_ton_box_4",required=false) @RequestParam(required = false) Double discharge_ton_box_4,
                         @ApiParam(name="kitchen_waste_under_sieve_4",value="kitchen_waste_under_sieve_4",required=false) @RequestParam(required = false) Double kitchen_waste_under_sieve_4,
                         @ApiParam(name="remark",value="remark",required=false) @RequestParam(required = false) String remark) {
        SjqCompostCraft record = new SjqCompostCraft();
        record.setId(id);
        record.setDate(date);

        record.setRawMaterial1(raw_material_1);
        record.setPeat1(peat_1);
        record.setBackfillFertilizer1(backfill_fertilizer_1);
        record.setWoodMatrix1(wood_matrix_1);
        record.setOutput1(output_1);

        record.setTontankFeed2(tontank_feed_2);
        record.setDisposalKitchenWaste2(disposal_kitchen_waste_2);
        record.setPeat2(peat_2);
        record.setDriedKitchenWaste2(dried_kitchen_waste_2);
        record.setWoodMatrix2(wood_matrix_2);
        record.setDischargeTonBox2(discharge_ton_box_2);
        record.setKitchenWasteUnderSieve2(kitchen_waste_under_sieve_2);

        record.setTontankFeed3(tontank_feed_3);
        record.setDisposalKitchenWaste3(disposal_kitchen_waste_3);
        record.setPeat3(peat_3);
        record.setDriedKitchenWaste3(dried_kitchen_waste_3);
        record.setWoodMatrix3(wood_matrix_3);
        record.setDischargeTonBox3(discharge_ton_box_3);
        record.setKitchenWasteUnderSieve3(kitchen_waste_under_sieve_3);

        record.setTontankFeed4(tontank_feed_4);
        record.setDisposalKitchenWaste4(disposal_kitchen_waste_4);
        record.setPeat4(peat_4);
        record.setDriedKitchenWaste4(dried_kitchen_waste_4);
        record.setWoodMatrix4(wood_matrix_4);
        record.setDischargeTonBox4(discharge_ton_box_4);
        record.setKitchenWasteUnderSieve4(kitchen_waste_under_sieve_4);

        record.setRemark(remark);


    return ResultGenerator.genSuccessResult(sjqCompostCraftService.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间(时间戳：毫秒)") @RequestParam(required = false) Long startTime,
                         @ApiParam(name="endTime",value="截止时间(时间戳：毫秒)") @RequestParam(required = false) Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqCompostCraftService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqCompostCraftService.getByTime(pageSize, currentPage, startTime, endTime));
    }


}
